import router from "./router";
//引入大仓库
import pinia from "./store";
//引入用户小仓库
import useUserStore from "./store/modules/user";
//在调用pinia的某个store是可以传递第一个参数来指定pinia的值，也就是他没有找到pinia实例
let useStore = useUserStore(pinia)
router.beforeEach((to, _from, next) => {
    //获取user
    const user = useStore.user;
    
    if (user && user._id) {
        //user信息存在如果继续登录页面则直接进入首页
        if (to.path == "/login") {
            next({ path: '/' })
        }else{
            next()
        }
    } else {
        if(to.path==="/login"){
            next();
        }else{
            next({path:'/login'})
        }
    }
})